package ArithUtils;

import Utils.ByteTree;

/**
 * A class which represents MyBoolean -
 * the element of the array of booleans.
 * 
 * @author Itamar Carmel
 */
public class MyBoolean {

	// suppose mb = (val); val = true/false
	private boolean val; //val
	private final static boolean TRUE = true; // 'true' in BT rep.
	private final static boolean FALSE = false; // 'false' in BT rep.
	
	/**
	 * Constructor for MyBoolean from 'val' in byte array rep.
	 * 
	 * @param b
	 */
	public MyBoolean(boolean b){
		this.val = b;
	}
	
	/**
	 * Returns fixed array of MBs from given integers.
	 * 
	 * @param N0
	 * @param N
	 * @return MB_array; MB_array[i] = (i < N) ? TRUE : FALSE; MB_array.length = N0.
	 */
	public static Array<MyBoolean> setDefaultArray(int N0, int N) {
		Array<MyBoolean> MBArr = new Array<MyBoolean>();
		for (int i=0; i<N0; i++){
			MBArr.add(new MyBoolean((i<N) ? TRUE : FALSE));
		}
		return MBArr; 
	}

	/**
	 * Return boolean value of 'val'.
	 * 
	 * @return true / false (val)
	 */
	public boolean isTrue() {
		return this.val;
	}

	/**
	 * Returns an array of MBs from its BT rep.
	 * 
	 * @param bt
	 * @return MB_Arr(bt)
	 */
	public static Array<MyBoolean> BTToArrayOfMyBoolean(ByteTree bt) {
		Array<MyBoolean> MBArr = new Array<MyBoolean>();
		String str = bt.toString();
		for (int i=0; i<bt.getSizeOfData(); i++){
			MBArr.add(new MyBoolean((str.charAt(i*2+1)=='1') ? TRUE : FALSE));
		}
		return MBArr;
	}
	
	public String toString(){
		if (this.isTrue())
			return "TRUE";
		else
			return "FALSE";
	}

}
